<template>
  <div class="AllGoods">
    <a-card>
      <a-form :form="form">
        <a-row :gutter="30">
          <a-col :span="8">
            <a-form-item
              label="商品名称"
              :label-col="{ span: 6 }"
              :wrapper-col="{ span: 16, offset: 1 }"
            >
              <a-input
                placeholder="请输入"
                v-decorator="[
          'goodsName',
          {rules: [{ required: true, message: '请输入商品名称!' }]}
        ]"
              />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="商品ID" :label-col="{ span: 6}" :wrapper-col="{ span: 16, offset: 1}">
              <a-input
                placeholder="请输入"
                v-decorator="[
          'goodsId',
          {rules: [{ required: true, message: '请输入商品ID!' }]}
        ]"
              />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item
              label="商品条码"
              :label-col="{ span: 6 }"
              :wrapper-col="{ span: 16, offset: 1}"
            >
              <a-input
                placeholder="请输入"
                v-decorator="[
          'goodsFridgecode',
          {rules: [{ required: true, message: '请输入商品条码!' }]}
        ]"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="30">
          <a-col :span="8">
            <a-form-item label="商品分类" :label-col="{ span: 6 }" :wrapper-col="{ span: 16,offset:1}">
              <a-select
                v-decorator="[
          'goodsClassify',
          {rules: [{ required: true, message: '请选择商品分类!' }]}
        ]"
                placeholder="全部"
              >
                <a-select-option value="1">全部</a-select-option>
                <a-select-option value="2">零食</a-select-option>
                <a-select-option value="3">饮料</a-select-option>
                <a-select-option value="4">标签</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="创建时间" :label-col="{ span: 6 }" :wrapper-col="{ span: 16,offset:1 }">
              <a-range-picker
                style="width: 100%"
                v-decorator="['range-time-picker', rangeConfig]"
                show-time
                format="YYYY-MM-DD HH:mm:ss"
              />
            </a-form-item>
          </a-col>
          <a-col :span="7" style="text-align:right;">
            <a-form-item>
              <a-button type="primary" @click="search">查询</a-button>
              <a-button type="dashed" style="margin:0 12px" @click="exportAgentGoods">导出</a-button>
              <!--  -->
              <a-button htmlType="reset">重置</a-button>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="0">
          <a-col :span="24">
            <p>温馨提示：未知商品可以进行价格修改，后续订单中的未知商品都将按照您设置的价格进行扣费。</p>
          </a-col>
        </a-row>
      </a-form>
    </a-card>
    <a-card style="margin-top:2%">
      <a-tabs defaultActiveKey="1" @change="callback">
        <a-tab-pane tab="我的商品库" key="1">
          <a-button type="primary" @click="Unknown">配置未知商品</a-button>
          <a-button type="primary" style="margin-left:1%" @click="PriceSetting">设置网点价</a-button>
          <a-table
            style="margin-top:2%"
            :columns="columns"
            :dataSource="data"
            @change="handleTableChange"
            :pagination="pagination"
            :rowKey="record => record.agencyGoodsId"
          >
            <template slot="goodsName" slot-scope="text,record">
              <editable-cell
                :text="text"
                @change="agencyNameChange(record.key, 'agencyName', $event,text,record)"
              />
            </template>
            <template slot="goodsLabel" slot-scope="text,record">
              <img style="width:100%" :src="record.imageUrl" alt>
            </template>
            <template slot="exhibitImg" slot-scope="text,record">
              <img style="width:100%" :src="record.imageDisplayUrl" alt>
            </template>
            <template slot="alterPrice" slot-scope="text,record">
              <span class="blue" @click="areModal(text,record)">查看</span>
            </template>
            <template slot="operate" slot-scope="text,record">
              <span class="remove" @click="removeConfirm(text,record)">移除</span>
              <span class="details" @click="detailsModal">详情</span>
            </template>
            <span slot="isShelves">
              <span>待上架</span>
            </span>
          </a-table>
        </a-tab-pane>
        <a-tab-pane tab="总商品库" key="2" forceRender>
          <a-table
            style="margin-top:2%"
            :columns="columnsAll"
            :dataSource="dataAll"
            @change="TableAll"
            :pagination="paginationAll"
            :rowKey="record => record.id"
          >
            <template slot="goodsImg" slot-scope="text,record">
              <img :src="record.imageUrl" style="width:100%" alt="图片加载不成功">
            </template>
            <template slot="exhibitImg" slot-scope="text,record">
              <img :src="record.imageDisplayUrl" style="width:100%" alt="图片加载不成功">
            </template>
            <template slot="operate" slot-scope="text,record">
              <span
                :class="record.has_add==0?'blue':''"
                @click="record.has_add==0?addModal(text):''"
              >{{record.has_add==0?"添加到我的商品库":"已加入我的商品库"}}</span>
            </template>
          </a-table>
        </a-tab-pane>
      </a-tabs>
    </a-card>
    <a-modal title="配置未知商品价格" :visible="Unknownvisible" @ok="UnknownOk" @cancel="UnknownCancel">
      <a-form :form="form">
        <a-form-item label="商品名称" :label-col="{ span: 6 }">
          <span style="margin-left:4%">未知</span>
        </a-form-item>
        <a-form-item label="销售价" :label-col="{ span: 6 }" :wrapper-col="{ span: 12, offset: 1 }">
          <a-input
            placeholder="请输入"
            v-decorator="[
          'salesPriceUnknown', { initialValue: '0.01' },
          {rules: [{ required: true, message: '请输入销售价!' }]}
        ]"
          />
        </a-form-item>
      </a-form>
    </a-modal>
    <a-modal
      title="设置网点价格"
      :visible="PriceSettingvisible"
      @ok="PriceSettingOk"
      @cancel="PriceSettingCancel"
      :width="800"
    >
      <a-form :form="form">
        <a-row :gutter="30">
          <a-col :span="12">
            <a-form-item label="选择网点" :label-col="{ span: 6 }" :wrapper-col="{ span: 16,offset:1 }">
              <a-select
                v-decorator="[
          'selectSite',
          {rules: [{ required: true, message: '请选择选择网点!' }]}
        ]"
                placeholder="全部"
              >
                <a-select-option
                  v-for="item in branchSelect"
                  :key="item.branchId"
                  :value="item.branchId"
                >{{item.name}}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
        <hr>
        <a-row style="margin-top:2%" :gutter="30">
          <a-col :span="12">
            <a-form-item
              label="商品名称"
              :label-col="{ span: 6 }"
              :wrapper-col="{ span: 16, offset: 1 }"
            >
              <a-input
                placeholder="请输入"
                v-decorator="[
          'goodsName',
          {rules: [{ required: true, message: '请输入商品名称!' }]}
        ]"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-button type="primary" style="margin-right:3%" @click="findPageListByBranchs">查询</a-button>
            <a-button htmlType="reset">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
      <a-table
        style="margin-top:2%"
        :columns="columnsPop"
        :dataSource="dataPop"
        @change="TablePop"
        :rowKey="record => record.id"
        :bordered="true"
        :pagination="paginationPop"
      >
        <template slot="goodsPrice" slot-scope="text,record">
          <editable-cell
            :text="text"
            @change="onCellChange(record.key, 'goodsPrice', $event,text,record)"
          />
        </template>
      </a-table>
    </a-modal>
    <a-modal :title="areTitle" :visible="arevisible" @ok="areOk" @cancel="areCancel" :width="800">
      <a-table
        style="margin-top:2%"
        :columns="columnsAre"
        :dataSource="dataAre"
        @change="TableAre"
        :rowKey="record => record.id"
        :bordered="true"
        :pagination="paginationAre"
      ></a-table>
    </a-modal>
    <a-modal title="添加到商品库" :visible="addVisible" @ok="addOk" @cancel="addCancel">
      <a-form :form="form">
        <a-form-item label="商品名称" :label-col="{ span: 6 }" :wrapper-col="{ span: 16, offset: 1 }">
          <span>{{goodsName}}</span>
        </a-form-item>
        <a-form-item label="销售价" :label-col="{ span: 6 }" :wrapper-col="{ span: 12, offset: 1 }">
          <a-input
            placeholder="请输入销售价格"
            v-decorator="[
          'salesPrice',
          {rules: [{ required: true, message: '请输入销售价!' }]}
        ]"
          />
        </a-form-item>
      </a-form>
    </a-modal>
    <a-modal title="详情查看" :visible="detailsVisible" @ok="detailsOk" @cancel="detailsCancel">
      <a-table
        style="margin-top:2%"
        :columns="columnsDetails"
        :dataSource="dataDetails"
        @change="TableDetails"
        :rowKey="record => record.key"
        :bordered="true"
        :pagination="false"
      ></a-table>
      <p style="margin-top:4%">日志管理</p>
      <a-table
        style="margin-top:2%"
        :columns="columnsLogs"
        :dataSource="dataLogs"
        @change="TableLogs"
        :rowKey="record => record.key"
        :bordered="true"
        :pagination="false"
      ></a-table>
    </a-modal>
  </div>
</template>

<script>
import moment from "moment";
import EditableCell from "../../components/EditableCell";
const columns = [
  {
    title: "商品ID",
    dataIndex: "code",
    key: "goodsID",
    scopedSlots: { customRender: "goodsID" },
    align: "center"
  },
  {
    title: "商品名称",
    dataIndex: "agencyName",
    key: "goodsName",
    scopedSlots: { customRender: "goodsName" },
    align: "center"
  },
  {
    title: "商品标签",
    dataIndex: "imageUrl",
    key: "goodsLabel",
    scopedSlots: { customRender: "goodsLabel" },
    align: "center",
    width: "12%"
  },
  {
    title: "占用列",
    key: "colspann",
    dataIndex: "placementNumber",
    scopedSlots: { customRender: "colspann" },
    align: "center"
  },
  {
    title: "货道可放置数",
    key: "aisleNum",
    dataIndex: "occupancyColumn",
    scopedSlots: { customRender: "aisleNum" },
    align: "center"
  },
  {
    title: "商品陈列图",
    dataIndex: "exhibitImg",
    key: "exhibitImg",
    scopedSlots: { customRender: "exhibitImg" },
    align: "center",
    width: "12%"
  },
  {
    title: "商品条码",
    dataIndex: "barCode",
    key: "goodsFridgecode",
    scopedSlots: { customRender: "goodsFridgecode" },
    align: "center"
  },
  {
    title: "商品分类",
    dataIndex: "categoryName",
    key: "goodsCategory",
    scopedSlots: { customRender: "goodsCategory" },
    align: "center"
  },
  {
    title: "统一售价",
    dataIndex: "agencyPrice",
    key: "unifiedPrice",
    scopedSlots: { customRender: "unifiedPrice" },
    align: "center"
  },
  {
    title: "改价明细",
    dataIndex: "alterPrice",
    key: "alterPrice",
    scopedSlots: { customRender: "alterPrice" },
    align: "center"
  },
  {
    title: "创建时间",
    dataIndex: "createTime",
    key: "creationTime",
    scopedSlots: { customRender: "creationTime" },
    align: "center"
  },
  {
    title: "操作",
    dataIndex: "",
    key: "operate",
    scopedSlots: { customRender: "operate" },
    align: "center"
  }
];
// 设置网点价格列数据
const columnsPop = [
  {
    title: "商品ID",
    dataIndex: "goodsCode",
    key: "goodsID",
    scopedSlots: { customRender: "goodsID" },
    align: "center"
  },
  {
    title: "商品名称",
    dataIndex: "goodsName",
    key: "goodsName",
    scopedSlots: { customRender: "goodsName" },
    align: "center"
  },
  {
    title: "商品售价",
    dataIndex: "price",
    key: "goodsPrice",
    scopedSlots: { customRender: "goodsPrice" },
    align: "center"
  }
];

// 总商品库列数据
const columnsAll = [
  {
    title: "商品ID",
    dataIndex: "code",
    key: "goodsID",
    scopedSlots: { customRender: "goodsID" },
    align: "center"
  },
  {
    title: "商品名称",
    dataIndex: "name",
    key: "goodsName",
    scopedSlots: { customRender: "goodsName" },
    align: "center"
  },
  {
    title: "商品图",
    dataIndex: "imageUrl",
    key: "goodsImg",
    scopedSlots: { customRender: "goodsImg" },
    align: "center",
    width: "12%"
  },
  {
    title: "占用列",
    key: "colspann",
    dataIndex: "placementNumber",
    scopedSlots: { customRender: "colspann" },
    align: "center"
  },
  {
    title: "货道可放置数",
    key: "aisleNum",
    dataIndex: "occupancyColumn",
    scopedSlots: { customRender: "aisleNum" },
    align: "center"
  },
  {
    title: "商品陈列图",
    dataIndex: "imageDisplayUrl",
    key: "exhibitImg",
    scopedSlots: { customRender: "exhibitImg" },
    align: "center",
    width: "12%"
  },
  {
    title: "商品条码",
    dataIndex: "barCode",
    key: "goodsFridgecode",
    scopedSlots: { customRender: "goodsFridgecode" },
    align: "center"
  },
  {
    title: "商品分类",
    dataIndex: "categoryName",
    key: "goodsCategory",
    scopedSlots: { customRender: "goodsCategory" },
    align: "center"
  },
  {
    title: "创建时间",
    dataIndex: "createTime",
    key: "creationTime",
    scopedSlots: { customRender: "creationTime" },
    align: "center"
  },
  {
    title: "操作",
    dataIndex: "",
    key: "operate",
    scopedSlots: { customRender: "operate" },
    align: "center"
  }
];

// 改价详情
const columnsAre = [
  {
    title: "网点名称",
    dataIndex: "branchName",
    key: "networkName",
    scopedSlots: { customRender: "networkName" },
    align: "center"
  },
  {
    title: "商品售价",
    dataIndex: "price",
    key: "goodsPrice",
    scopedSlots: { customRender: "goodsPrice" },
    align: "center"
  }
];

// 详情查看
const columnsDetails = [
  {
    title: "商品ID",
    dataIndex: "goodsID",
    key: "goodsID",
    scopedSlots: { customRender: "goodsID" },
    align: "center"
  },
  {
    title: "商品名称",
    dataIndex: "goodsName",
    key: "goodsName",
    scopedSlots: { customRender: "goodsName" },
    align: "center"
  },
  {
    title: "占用列",
    key: "colspann",
    dataIndex: "colspann",
    scopedSlots: { customRender: "colspann" },
    align: "center"
  },
  {
    title: "货道可放置数",
    key: "aisleNum",
    dataIndex: "aisleNum",
    scopedSlots: { customRender: "aisleNum" },
    align: "center"
  },
  {
    title: "商品陈列图",
    dataIndex: "exhibitImg",
    key: "exhibitImg",
    scopedSlots: { customRender: "exhibitImg" },
    align: "center"
  }
];

// 日志管理
const columnsLogs = [
  {
    title: "时间",
    dataIndex: "time",
    key: "time",
    scopedSlots: { customRender: "time" },
    align: "center"
  },
  {
    title: "操作人员",
    dataIndex: "operationStaff",
    key: "operationStaff",
    scopedSlots: { customRender: "operationStaff" },
    align: "center"
  },
  {
    title: "操作内容",
    dataIndex: "operationalContext",
    key: "operationalContext",
    scopedSlots: { customRender: "operationalContext" },
    align: "center"
  }
];

const data = [
  {
    key: 1
  }
];

const dataPop = [
  {
    key: 1,
    goodsID: "1"
  }
];

const dataAll = [
  {
    key: 1
  }
];

const dataAre = [
  {
    key: 1
  }
];

const dataDetails = [
  {
    key: 1
  }
];

const dataLogs = [
  {
    key: 1
  }
];
export default {
  name: "AllGoods",
  data() {
    return {
      form: this.$form.createForm(this),
      dateFormat: "YYYY/MM/DD",
      monthFormat: "YYYY/MM",
      data: [],
      columns,
      visible: false,
      columnsPop,
      dataPop: [],
      columnsAll,
      dataAll: [],
      columnsAre,
      dataAre: [],
      columnsDetails,
      dataDetails: [],
      columnsLogs,
      dataLogs: [],
      arevisible: false,
      addVisible: false,
      Unknownvisible: false,
      PriceSettingvisible: false,
      detailsVisible: false,
      pagination: {
        showSizeChanger: true,
        showQuickJumper: true,
        pageSizeOptions: ["2", "4", "8", "10", "12"],
        showTotal: (total, range) => {
          return `${range[0]}-${range[1]} 共${total}条`;
        },
        pageSize: 3,
        defaultCurrent: 1,
        current: 1,
        total: 5
      },
      paginationAll: {
        showSizeChanger: true,
        showQuickJumper: true,
        pageSizeOptions: ["2", "4", "8", "10", "12"],
        showTotal: (total, range) => {
          return `${range[0]}-${range[1]} 共${total}条`;
        },
        pageSize: 3,
        defaultCurrent: 1,
        current: 1,
        total: 5
      },
      paginationPop: {
        showSizeChanger: true,
        showQuickJumper: true,
        pageSizeOptions: ["2", "4", "8", "10", "12"],
        showTotal: (total, range) => {
          return `${range[0]}-${range[1]} 共${total}条`;
        },
        pageSize: 10,
        defaultCurrent: 1,
        current: 1,
        total: 5
      },
      paginationAre: {
        showSizeChanger: true,
        showQuickJumper: true,
        pageSizeOptions: ["2", "4", "8", "10", "12"],
        showTotal: (total, range) => {
          return `${range[0]}-${range[1]} 共${total}条`;
        },
        pageSize: 5,
        defaultCurrent: 1,
        current: 1,
        total: 5
      },
      rangeConfig: {
        rules: [
          { type: "array", required: true, message: "Please select time!" }
        ]
      },
      goodsName: "",
      branchSelect: [],
      areTitle: "",
      isEditIcon: false,
      isWin: false,
      isPriceCancel: false,
      isInput: false,
      isprice: true
    };
  },
  components: {
    EditableCell
  },
  watch: {},
  methods: {
    editPrice() {
      this.isWin = true;
      this.isPriceCancel = true;
      this.isInput = true;
      this.isprice = false;
    },
    goodsPriceEnter(index) {
      this.isEditIcon = true;
    },
    goodsPriceLeave(index) {
      this.isEditIcon = false;
    },
    priceCancel() {
      this.isPriceCancel = false;
      this.isWin = false;
      this.isEditIcon = true;
      this.isInput = false;
      this.isprice = true;
    },
    agencyNameChange(key, dataIndex, value, text, record) {
      const dataSource = [...this.dataPop];
      const target = dataSource.find(item => item.id === key);
      if (target) {
        target[dataIndex] = value;
        this.dataPop = dataSource;
      }
      // var priceId = record.id;
      // this.$store.commit("priceId", priceId);
    },
    onCellChange(key, dataIndex, value, text, record) {
      const dataSource = [...this.dataPop];
      const target = dataSource.find(item => item.id === key);
      if (target) {
        target[dataIndex] = value;
        this.dataPop = dataSource;
      }
      var priceId = record.id;
      this.$store.commit("priceId", priceId);
    },

    callback(key) {
      if (key == 1) {
        this.search();
      }
      if (key == 2) {
        this.findPageListRelationAgentByCondition();
      }
    },
    Unknown() {
      this.Unknownvisible = true;
    },
    UnknownOk(e) {
      this.Unknownvisible = false;
      this.addUnknownGoods();
    },
    UnknownCancel(e) {
      console.log("Clicked cancel button");
      this.Unknownvisible = false;
    },
    PriceSetting() {
      this.PriceSettingvisible = true;
      this.editBranchesPriceListInit();
      this.findPageListByBranchs();
    },
    PriceSettingOk(e) {
      this.PriceSettingvisible = false;
    },
    PriceSettingCancel(e) {
      console.log("点击取消按钮了");
      this.PriceSettingvisible = false;
    },
    handleMenuClick(e) {
      console.log("click", e);
    },
    moment,
    onChange(dates, dateStrings) {
      console.log("From: ", dates[0], ", to: ", dates[1]);
      console.log("From: ", dateStrings[0], ", to: ", dateStrings[1]);
    },
    handleTableChange(pagination, filters, sorter) {
      const pager = { ...this.pagination };
      pager.current = pagination.current;
      pager.pageSize = pagination.pageSize;
      pager.total = pagination.total;
      this.pagination = pager;
      this.search();
    },
    TablePop(pagination, filters, sorter) {
      const pager = { ...this.paginationPop };
      pager.current = pagination.current;
      pager.pageSize = pagination.pageSize;
      pager.total = pagination.total;
      this.paginationPop = pager;
      this.findPageListByBranchs();
    },
    TableAll(pagination, filters, sorter) {
      const pager = { ...this.paginationAll };
      pager.current = pagination.current;
      pager.pageSize = pagination.pageSize;
      pager.total = pagination.total;
      this.paginationAll = pager;
      this.findPageListRelationAgentByCondition();
    },
    TableAre(pagination, filters, sorter) {
      const pager = { ...this.paginationAre };
      pager.current = pagination.current;
      pager.pageSize = pagination.pageSize;
      pager.total = pagination.total;
      this.paginationAre = pager;
      this.findPageListByGoods(this.goodsId);
    },
    TableDetails(pagination, filters, sorter) {
      const pager = { ...this.pagination };
      pager.current = pagination.current;
      pager.pageSize = pagination.pageSize;
      pager.total = pagination.total;
      this.pagination = pager;
      this.search();
    },
    TableLogs(pagination, filters, sorter) {
      const pager = { ...this.pagination };
      pager.current = pagination.current;
      pager.pageSize = pagination.pageSize;
      pager.total = pagination.total;
      this.pagination = pager;
      this.search();
    },
    showModal() {
      this.visible = true;
    },
    handleOk(e) {
      this.visible = false;
    },
    handleCancel(e) {
      console.log("点击取消了");
      this.visible = false;
    },
    areModal(text, record) {
      this.arevisible = true;
      this.goodsId = record.id;
      this.areTitle = record.agencyName + "-改价详情";
      this.findPageListByGoods(this.goodsId);
    },
    areOk(e) {
      this.arevisible = false;
    },
    areCancel(e) {
      console.log("点击取消了");
      this.arevisible = false;
    },
    // 添加到商品库
    addModal(text) {
      this.addVisible = true;
      this.goodsName = text.name;
      this.text = text;
    },
    addOk(e) {
      this.addVisible = false;
      this.addAgentGoods(this.text);
    },
    addCancel(e) {
      console.log("点击取消了");
      this.addVisible = false;
    },
    // 详情弹出框操作
    detailsModal() {
      this.detailsVisible = true;
    },
    detailsOk(e) {
      this.detailsVisible = false;
    },
    detailsCancel(e) {
      console.log("点击取消了");
      this.detailsVisible = false;
    },
    // 是否移除方法
    removeConfirm(text, record) {
      var that = this;
      this.id = text.id;
      this.agencyGoodsId = text.agencyGoodsId;
      console.log(text);
      this.$confirm({
        title: "移除商品",
        content: "您确定要移除这个商品吗？",
        okText: "确定",
        cancelText: "取消",
        iconType: "question-circle",
        onOk() {
          console.log("确定");
          that.delAgentGoods(that.id, that.agencyGoodsId);
        },
        onCancel() {
          console.log("取消");
        }
      });
    },
    // 列表初始化
    listInit() {
      this.axios
        .post(this.baseUrl + "/goods/listInit", {
          loginToken: this.$store.state.loginToken
        })
        .then(response => {
          // console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 查询代理商商品库列表
    search() {
      var values = this.form.getFieldsValue();
      this.axios
        .post(
          this.baseUrl +
            "/goods/findAgentGoodsPageListRelationGoodsByCondition",
          {
            loginToken: this.$store.state.loginToken,
            pageNum: this.pagination.current,
            pageSize: this.pagination.pageSize,
            name: values.goodsName
          }
        )
        .then(response => {
          // console.log(response);
          this.data = response.data.data.list;
          this.pagination.total = response.data.data.total;
          this.pagination.pageSize = response.data.data.pageSize;
          this.pagination.current = response.data.data.pageNum;
        })
        .catch(error => {
          console.log(error);
        });
    },

    // 查询总商品库列表
    findPageListRelationAgentByCondition() {
      var values = this.form.getFieldsValue();
      this.axios
        .post(this.baseUrl + "/goods/findPageListRelationAgentByCondition", {
          loginToken: this.$store.state.loginToken,
          pageNum: this.paginationAll.current,
          pageSize: this.paginationAll.pageSize,
          name: values.goodsName
        })
        .then(response => {
          // console.log(response);
          this.dataAll = response.data.data.list;
          this.paginationAll.total = response.data.data.total;
          this.paginationAll.pageSize = response.data.data.pageSize;
          this.paginationAll.current = response.data.data.pageNum;
        })
        .catch(error => {
          console.log(error);
        });
    },

    // 查询网点价格根据网点相关
    findPageListByBranchs() {
      var values = this.form.getFieldsValue();
      this.axios
        .post(this.baseUrl + "/goods/findPageListByBranchs", {
          loginToken: this.$store.state.loginToken,
          pageNum: this.paginationPop.current,
          pageSize: this.paginationPop.pageSize
        })
        .then(response => {
          // console.log(response);
          this.dataPop = response.data.data.list;
          this.paginationPop.total = response.data.data.total;
          this.paginationPop.pageSize = response.data.data.pageSize;
          this.paginationPop.current = response.data.data.pageNum;
        })
        .catch(error => {
          console.log(error);
        });
    },

    // 查询网点价格根据商品相关
    findPageListByGoods(goodsId) {
      var values = this.form.getFieldsValue();
      this.axios
        .post(this.baseUrl + "/goods/findPageListByGoods", {
          loginToken: this.$store.state.loginToken,
          pageNum: this.paginationAre.current,
          pageSize: this.paginationAre.pageSize,
          goodsId: goodsId
        })
        .then(response => {
          // console.log(response);
          this.dataAre = response.data.data.list;
          this.paginationAre.total = response.data.data.total;
          this.paginationAre.pageSize = response.data.data.pageSize;
          this.paginationAre.current = response.data.data.pageNum;
        })
        .catch(error => {
          console.log(error);
        });
    },

    // 添加到我的商品库
    addAgentGoods(text) {
      var values = this.form.getFieldsValue();
      this.axios
        .post(this.baseUrl + "/goods/addAgentGoods", {
          loginToken: this.$store.state.loginToken,
          agencyPrice: values.salesPrice,
          goodsId: text.id
        })
        .then(response => {
          // console.log(response);
          if (response.data.code == 0) {
            this.findPageListRelationAgentByCondition();
            this.$message.info("添加成功");
          }
        })
        .catch(error => {
          console.log(error);
        });
    },

    // 添加到我的商品库-未知商品
    addUnknownGoods() {
      var values = this.form.getFieldsValue();
      this.axios
        .post(this.baseUrl + "/goods/addAgentGoods", {
          loginToken: this.$store.state.loginToken,
          agencyPrice: values.salesPriceUnknown,
          goodsId: -1,
          agencyName: "未知商品"
        })
        .then(response => {
          console.log(response);
          // if (response.data.code == 0) {
          //   this.findPageListRelationAgentByCondition();
          // }
        })
        .catch(error => {
          console.log(error);
        });
    },

    // 移出我的商品库
    delAgentGoods(id, agencyGoodsId) {
      var values = this.form.getFieldsValue();
      this.axios
        .post(this.baseUrl + "/goods/delAgentGoods", {
          loginToken: this.$store.state.loginToken,
          goodsId: id,
          id: agencyGoodsId
        })
        .then(response => {
          console.log(response);
          if (response.data.code == 0) {
            this.$message.info("移除商品成功");
            this.search();
          }
          if (response.data.code == -1) {
            this.$message.error(response.data.msg);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },

    // 修改网点价初始化
    editBranchesPriceListInit() {
      this.axios
        .post(this.baseUrl + "/goods/editBranchesPriceListInit", {
          loginToken: this.$store.state.loginToken
        })
        .then(response => {
          // console.log(response);
          this.branchSelect = response.data.data;
        })
        .catch(error => {
          console.log(error);
        });
    },

    // 编辑我的商品库
    editAgentGoods(id, agencyGoodsId) {
      var values = this.form.getFieldsValue();
      this.axios
        .post(this.baseUrl + "/goods/editAgentGoods", {
          loginToken: this.$store.state.loginToken,
          agencyName: id,
          id: agencyGoodsId
        })
        .then(response => {
          console.log(response);
          if (response.data.code == 0) {
            this.$message.info("移除商品成功");
            this.search();
          }
        })
        .catch(error => {
          console.log(error);
        });
    },

    // 编辑我的商品库
    editBranchesPrice(id, agencyGoodsId) {
      var values = this.form.getFieldsValue();
      this.axios
        .post(this.baseUrl + "/goods/editBranchesPrice", {
          loginToken: this.$store.state.loginToken,
          id: id,
          price: agencyGoodsId
        })
        .then(response => {
          console.log(response);
          if (response.data.code == 0) {
            this.$message.info("移除商品成功");
            this.search();
          }
        })
        .catch(error => {
          console.log(error);
        });
    },

    // 导出我的商品库
    exportAgentGoods() {
      var values = this.form.getFieldsValue();
      this.axios
        .post(
          this.baseUrl + "/goods/exportAgentGoods",
          {
            loginToken: this.$store.state.loginToken,
            name: values.goodsName
          },
          { responseType: "arraybuffer" }
        )
        .then(response => {
          console.log(response);
          if (response.status == "200") {
            const aLink = document.createElement("a");
            let blob = new Blob([response.data], {
              type: "application/vnd.ms-excel"
            });
            aLink.href = URL.createObjectURL(blob);
            aLink.download = "代理商商品库表";
            aLink.click();
            document.body.appendChild(aLink);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },

    // 导出总商品库
    exportGoodsRelationAgent() {
      var values = this.form.getFieldsValue();
      this.axios
        .post(
          this.baseUrl + "/goods/exportGoodsRelationAgent",
          {
            loginToken: this.$store.state.loginToken,
            name: values.goodsName
          },
          { responseType: "arraybuffer" }
        )
        .then(response => {
          console.log(response);
          if (response.status == "200") {
            const aLink = document.createElement("a");
            let blob = new Blob([response.data], {
              type: "application/vnd.ms-excel"
            });
            aLink.href = URL.createObjectURL(blob);
            aLink.download = "总商品库表";
            aLink.click();
            document.body.appendChild(aLink);
          }
        })
        .catch(error => {
          console.log(error);
        });
    }
  },
  created() {
    this.listInit();
    this.search();
  },
  mounted() {}
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.AllGoods {
  width: 100%;
}
.alterPrice,
.add,
.edit,
.remove,
.details {
  color: rgb(0, 85, 255);
  cursor: pointer;
}
.line {
  display: inline-block;
  width: 1px;
  height: 16px;
  background: rgb(233, 233, 233);
  margin: 0 10px;
}
</style>
